import React from 'react';
import {Form, Input, Select, DatePicker, Row, Col, Radio} from 'antd';
import {formItemLayout, respond} from '../_/formItemLayout';
import form from '../_/form';
import {context} from '../_';
const _fil = formItemLayout.ignore,
    FormItem = Form.Item,
    RadioGroup = Radio.Group,
    Option = Select.Option,
    dataName = 'vdata';
import redux from '../_/redux';
@redux('department', {
    data: '_',
    prefix: 'department',
    actions: 'load'
})
@redux('dict', {
    prefix: 'insurance',
    data: 'insurance',
    loadArgs: [{params: {type: 'insurance'}}],
    actions: 'load'
})
@redux('dict', {
    prefix: 'charge',
    data: 'charge',
    loadArgs: [{params: {type: 'charge'}}],
    actions: 'load'
})
@context('params')
@form({
    data: dataName,
    newData: {
        Status: true,
        DisplayOrder: 0
    }
})
export default class visitInfoForm extends React.Component {
    state = {};

    componentWillReceiveProps(props) {
        switch (props.vIBactionTyp) {
        case "vIBsave" :
            this.props.form.validateFieldsAndScroll((errors, values) => {
                if (errors) {
                    props.doAction("err", "vIB", errors);
                    return;
                }
                if (typeof this.props.doAction === 'function') {
                    props.doAction("save", "vIB", values);
                }
            });
            break;
        case "reset":
            this.props.form.resetFields();
            if (typeof this.props.doAction === 'function') {
                props.doAction("reset", "vIB", {});
            }
            break;
        default:
            break;
        }
    }

    render() {
        const {form} = this.props;
        const {getFieldDecorator: fp} = form,
            sNumber = fp('SerialNumber', {
                rules: [
                    {
                        required: true,
                        message: '请输入门诊流水号'
                    }
                ]
            }),
            visitNo = fp('visitNo', {
                rules: [
                    {
                        required: true,
                        message: '请输入就诊序号'
                    }
                ]
            }),
            visitDate = fp('visitDate', {
                rules: [
                    {
                        type: "object",
                        required: true,
                        message: '请输入就诊日期'
                    }
                ]
            }),
            departmentItems = this.props.departmentdata || [],
            insuranceItems = this.props.insurancedata || [],
            chargeItems = this.props.chargedata || [],
            newlyDiagnosedItems = [{Id: "006", Name: "初诊"}, {Id: "007", Name: "复诊"}],
            egisteredsStatusItems = [{Id: "008", Name: "预约"}, {Id: "009", Name: "非预约"}],
            treatmentStatusItems = [{Id: "010", Name: "已接诊"}, {Id: "011", Name: "未接诊"}, {
                Id: "012",
                Name: "正在就诊"
            }, {Id: "013", Name: "患者挂起"}, {Id: "014", Name: "就诊完成"}],
            doctorItems = [{Id: "015", Name: "邓世忠"}, {Id: "016", Name: "孙宝善"}, {Id: "017", Name: "江艳荣"}];

        return (
            <Form
                horizontal
                onSubmit={this.handleSubmit}
            >
                {fp("Id")(<Input type="hidden"/>)}
                <Row>
                    <h3 className="pFormTitle">患者门诊信息</h3>
                    <Col {...respond}>
                        <FormItem
                            label="门诊流水号"
                            {..._fil}
                        >{sNumber(
                            <Input
                                placeholder="请输入门诊流水号"
                            />
                        )}
                        </FormItem>
                        <FormItem
                            label="就诊序号"
                            {..._fil}
                        >{visitNo(
                            <Input
                                placeholder="请输入就诊序号"
                            />
                        )}
                        </FormItem>
                        <FormItem
                            {..._fil}
                            label="初诊标志"
                        >
                            <RadioGroup>
                                {newlyDiagnosedItems.map(newlyDiagnosed =>
                                    <Radio
                                        value={(String)(newlyDiagnosed.Id)}
                                        key={`newlyDiagnosed_${newlyDiagnosed.Id.toString()}`}
                                    >
                                        {(String)(newlyDiagnosed.Name)}
                                    </Radio>)}
                            </RadioGroup>
                        </FormItem>
                        <FormItem
                            {..._fil}
                            label="挂号日期"
                        >
                            <DatePicker
                                fomat="YYYY-MM-DD"
                            />
                        </FormItem>
                        <FormItem
                            label="挂号状态"
                            {..._fil}
                        >
                            <Select
                                showSearch
                                placeholder="请选择就诊状态"
                                optionFilterProp="children"
                                notFoundContent="找不到..."
                            >
                                {egisteredsStatusItems.map(egisteredsStatus =>
                                    <Option
                                        value={(String)(egisteredsStatus.Id)}
                                        key={`egisteredsStatus_${egisteredsStatus.Id.toString()}`}
                                    >
                                        {(String)(egisteredsStatus.Name)}
                                    </Option>)}
                            </Select>
                        </FormItem>
                    </Col>
                    <Col {...respond}>
                        <FormItem
                            {..._fil}
                            label="就诊日期"
                        >
                            {visitDate(
                                <DatePicker
                                    fomat="YYYY-MM-DD"
                                />
                            )}
                        </FormItem>
                        <FormItem
                            label="就诊状态"
                            {..._fil}
                        >
                            <Select
                                showSearch
                                placeholder="请选择就诊状态"
                                optionFilterProp="children"
                                notFoundContent="找不到..."
                            >
                                {treatmentStatusItems.map(treatmentStatus =>
                                    <Option
                                        value={(String)(treatmentStatus.Id)}
                                        key={`treatmentStatus_${treatmentStatus.Id.toString()}`}
                                    >
                                        {(String)(treatmentStatus.Name)}
                                    </Option>)}
                            </Select>
                        </FormItem>
                        <FormItem
                            label="就诊医生"
                            {..._fil}
                        >
                            <Select
                                showSearch
                                placeholder="请选择就诊医生"
                                optionFilterProp="children"
                                notFoundContent="找不到..."
                            >
                                {doctorItems.map(doctor =>
                                    <Option
                                        value={(String)(doctor.Id)}
                                        key={`doctor_${doctor.Id.toString()}`}
                                    >
                                        {(String)(doctor.Name)}
                                    </Option>)}
                            </Select>
                        </FormItem>
                        <FormItem
                            label="就诊类别"
                            {..._fil}
                        >
                            <Input
                                placeholder="请输入就诊类别"
                            />
                        </FormItem>
                        <FormItem
                            label="就诊科室"
                            {..._fil}
                        >
                            <Select
                                showSearch
                                placeholder="请选择就诊科室"
                                optionFilterProp="children"
                                notFoundContent="找不到..."
                            >
                                {departmentItems.map(department =>
                                    <Option
                                        value={(String)(department.Id)}
                                        key={`department_${department.Id.toString()}`}
                                    >
                                        {(String)(department.Name)}
                                    </Option>)}
                            </Select>
                        </FormItem>
                        <FormItem
                            label="就诊专科"
                            {..._fil}
                        >
                            <Select
                                showSearch
                                placeholder="请选择就诊专科"
                                optionFilterProp="children"
                                notFoundContent="找不到..."
                            >
                                {departmentItems.map(department =>
                                    <Option
                                        value={(String)(department.Id)}
                                        key={`insurance_${department.Id.toString()}`}
                                    >{(String)(department.Name)}
                                    </Option>)}
                            </Select>
                        </FormItem>
                    </Col>
                    <Col {...respond}>
                        <FormItem
                            label="医疗保险号"
                            {..._fil}
                        >
                            <Input
                                placeholder="请输入医疗保险号"
                            />
                        </FormItem>
                        <FormItem
                            label="医保类别"
                            {..._fil}
                        >
                            <Select
                                showSearch
                                placeholder="请选择医保类别"
                                optionFilterProp="children"
                                notFoundContent="找不到..."
                            >
                                {insuranceItems.map(insurance =>
                                    <Option
                                        value={(String)(insurance.Id)}
                                        key={`insurance_${insurance.Id.toString()}`}
                                    >
                                        {(String)(insurance.Name)}
                                    </Option>)}
                            </Select>
                        </FormItem>
                        <FormItem
                            label="费别"
                            {..._fil}
                        >
                            <Select
                                showSearch
                                placeholder="请选择费别"
                                optionFilterProp="children"
                                notFoundContent="找不到..."
                            >
                                {chargeItems.map(charge =>
                                    <Option
                                        value={(String)(charge.Id)}
                                        key={`charge_${charge.Id.toString()}`}
                                    >
                                        {(String)(charge.Name)}
                                    </Option>)}
                            </Select>
                        </FormItem>
                        <FormItem
                            label="症状"
                            {..._fil}
                        >
                            <Input
                                type="textarea"
                                rows={7}
                            />
                        </FormItem>
                    </Col>
                </Row>

            </Form>
        );
    }
}
